<?php
add_js('plugins/frontend/jquery.mousewheel.min', 'footer', 11);
add_js('plugins/frontend/jquery.jqzoom-core', 'footer', 11);
add_js('plugins/frontend/fancybox/jquery.fancybox', 'footer', 6);
add_js('plugins/frontend/fancybox/jquery.fancybox-buttons', 'footer', 9);
add_js('plugins/frontend/fancybox/jquery.fancybox-media', 'footer', 9);
add_js('plugins/frontend/fancybox/jquery.fancybox-thumbs', 'footer', 9);
add_js('plugins/lancesOperations', 'footer', 9);
add_js('plugins/frontend/jquery.maskMoney', 'footer', 9);
add_css('frontend/fancybox/jquery.fancybox', 'header', 13);
add_css('frontend/fancybox/helpers/jquery.fancybox-buttons', 'header', 14);
add_css('frontend/fancybox/helpers/jquery.fancybox-thumbs', 'header', 15);
add_css('frontend/jquery.jqzoom', 'footer', 16);
$favoritos_itens = array();

if (count($favoritos_user) > 0) {
    foreach ($favoritos_user as $fav):
        $favoritos_itens[] = $fav->LOTE_ID;
    endforeach;
}
$cont = 0;
?>
<div
    class="col-md-8 col-lg-9 col-xs-12 col-sm-12 container-list-leiloes ">


    <div class="navbar-painel">
        <div class="header">
            <div class="paginate-maxlive pull-left">
                <a href="#next" class="maxlive-nav"><i class="fa fa-angle-left"></i></a>
                Paginas 1 / 1 <a href="#next" class="maxlive-nav"><i
                        class="fa fa-angle-right"></i></a>
            </div>
            <ul class="header-info-status">
                <li><span><?php echo (int) $lotes['0']->TOTAL_LOTES; ?></span>Total
                    de Lotes</li>
                <li><span><?php echo (int) $lotes['0']->LANCES_LEILAO; ?></span>Lances</li>
                <li><span><?php echo (int) $lotes['0']->COMPRADORES_LEILAO; ?></span>Comprados
                </li>
                <li><span><?php echo (int) $lotes['0']->HABILITADOS; ?></span>Habilitados</li>
            </ul>
            <div class="clearfix"></div>
        </div>

    </div>




    <ul class="maxlive-ul">
        <?php if ($lotes) : ?>
            <?php foreach ($lotes as $key => $lote) : ?>
                <?php $date_end = $lote->FECHAMENTO; ?>
                <?php $rw = !is_null($lote->TEMPO_EXTRA) ? $lote->TEMPO_EXTRA : false; ?>
                <?php if ($rw && strtotime($lote->FECHAMENTO) < $lote->TEMPO_EXTRA): ?>
                    <?php //$is_show_lance = compare_date_max(date('Y-m-d H:i:s'), $lote->TEMPO_EXTRA); ?> 
                    <?php $date_end = date('Y-m-d H:i:s', $lote->TEMPO_EXTRA); ?> 
                <?php endif; ?>
                <?php
                /* has item in favorites user */ $has_favorite = 'fa-star-o';
                $has_lote_favorite = '';
                $on_fav = '';
                ?>
                <?php if (in_array($lote->ID, $favoritos_itens) && count($favoritos_user) > 0): ?>
                    <?php
                    $has_favorite = 'fa-star';
                    $has_lote_favorite = 'lote-favorite';
                    $on_fav = 'show-favorites';
                    ?>  
        <?php endif; ?>

                <li class="col-md-4 col-lg-3 col-sm-4  col-xs-12 maxlive-ul-li item-clock-<?php echo $lote->ID; ?>"
                    user-lote="0"
                    data-lote-id="<?php echo $lote->ID; ?>"
                    data-le-id="<?php echo $lote->LEILAO_ID; ?>" <?php echo $has_lote_favorite; ?>>


                    <div class="box-lote-maxlive">
                        <div class="data-info">

                            <?php if (userData()->id > 0 AND in_array($lote->ID, $favoritos_itens, TRUE)): ?>

                                <a href="<?php echo site_url('removeFavoritos/' . $lote->ID . '?r=' . uri_string()); ?>" class="label-lote-info-maxlive"> 
                                    <i class="fa <?php echo $has_favorite; ?>"></i> Lote <?php echo str_num_lote_pad($lote->NUM_LOTE); ?>
                                </a> 
        <?php endif; ?>
                            <?php if (userData()->id > 0 && !in_array($lote->ID, $favoritos_itens, TRUE)): ?>

                                <a href="<?php echo site_url('addFavoritos/' . $lote->ID . '?r=' . uri_string()); ?>" class="label-lote-info-maxlive"> 
                                    <i class="fa <?php echo $has_favorite; ?>"></i> Lote <?php echo str_num_lote_pad($lote->NUM_LOTE); ?>
                                </a> 
        <?php endif; ?>

                            <?php if (userData()->id == 0): ?>
                                <span class="label-lote-info-maxlive"> 
                                    <i class="fa <?php echo $has_favorite; ?>" show-message-login></i> Lote <?php echo str_num_lote_pad($lote->NUM_LOTE); ?>
                                </span> 
        <?php endif; ?>
                            <span class="group-lote-info-maxlive">G1</span> 
        <?php if (is_null($lote->VENDIDO) || $lote->CLOSED == 'N'): ?>
                                <span
                                    class="clock-lote-info-maxlive clock-lote-info-data lote-<?php echo $lote->ID; ?>" 
                                    data-lote-id="<?php echo $lote->ID; ?>"
                                    data-leilao-id="<?php echo $lote->LEILAO_ID; ?>"
                                    data-count="<?php echo $date_end; ?>"><?php echo extract_time($date_end); ?></span>
                                    <?php else: ?>
                                <span
                                    class="clock-lote-info-maxlive" 
                                    data-lote-id="<?php echo $lote->ID; ?>">
            <?php echo Utils::message('lote_closed'); ?> 
                                </span>
                            <?php endif; ?>
                            <div class="clearfix"></div>
                        </div>

                        <div class="tmb">
        <?php echo add_image('/lotes/' . render_first_image($lote->IMAGENS), 'class="img-painel"'); ?>
                        </div>
                        <div class="info-lote-maxlive">
                            <strong> <?php echo $lote->DESCRICAO; ?></strong> <?php echo $lote->SUB_DESCRICAO; ?> <br />
                            <span class="localizacao">
                                Local: <?php echo $lote->LOCALIZACAO; ?> - <?php echo $lote->UF; ?>
                            </span> <span class="maxlive-status-icons"> 
                                <?php if (!empty($lote->DESCRICAO_DETALHADA)): ?>
                                    <a href="#detalhes_<?php echo $lote->ID; ?>" title="LOTE <?php echo $lote->NUM_LOTE; ?>" class="icon-status detail-maxlive"></a>
                                <?php endif; ?>
                                <?php if (!empty($lote->IMAGENS)): ?>
                                    <a href="#gallery" class="icon-status gallery-maxlive" data-images='<?php render_to_gallery_painel($lote->IMAGENS); ?>'></a>
        <?php endif; ?>
        <?php if (!empty($lote->LINK)): ?>
                                    <a href="#videos" class="icon-status video-maxlive"></a>
        <?php endif; ?>
                                <a href="#lances" data-trigger-get-info-lances lote-id="<?php echo $lote->ID; ?>" class="painel-info-num-lances" title="Lances Ofertados"> <span><?php echo $lote->LANCES; ?></span></a>
                            </span>
                        </div>
                        <div class="info-lote-price">
                            <span class="increment">Incr: R$ <?php echo number_format($lote->INCREMENTO, 2, ',', '.'); ?></span>
                            <strong class="price-lote-maxlive ">R$ <span class="label-lance-ganhador"><?php
                            $lance = $lote->LAST_LANCE == null ? $lote->LANCE_INICIAL : $lote->LAST_LANCE;
                            echo number_format($lance, 2, ',', '.');
                            ?></span><span class="comissao">&nbsp; +<?php echo $lote->COMISSAO; ?>%</span></strong>
                        </div>
                        <div class="info-lote-user-maxlive">
                            <span class="login-maxlive label-ganhador">
                             <?php echo (string) $login = $lote->TIPO == 'A' ? $lote->GANHADOR . '(A)' : $lote->GANHADOR; ?></span>
                            
                            <?php 
                               
                               if($lote->GANHADOR == NULL){
                                   
                                   $infoMessageClosedLote =  '<span class="text-danger">SEM LANCE</span>';
                                    echo '<span class="status-maxlive ">'.$infoMessageClosedLote.'</span>';
                               }
                               if($lote->CLOSED == 'S' && $lote->CONDICIONAL == 'N'){
                                   $infoMessageClosedLote =  '<span class="text-success">VENDA</span>';
                                   echo '<span class="status-maxlive ">'.$infoMessageClosedLote.'</span>';
                               }
                               if($lote->CLOSED == 'S' && $lote->CONDICIONAL == 'S'){
                                   $infoMessageClosedLote =  '<span class="text-danger">'.lang_system('lote_closed_conditional').'</span>';
                                    echo '<strong class="status-maxliveC">'.$infoMessageClosedLote.'</strong>';
                               }
                               
                            ?>
                            <div class="clearfix">&nbsp;</div>
                        </div>
                    </div>
                    <div class="info-detalhes-box" style="width:400px; display:none;" id="detalhes_<?php echo $lote->ID ?>"  >
                        <div class="g-box">
                            <h3><?php echo $lote->DESCRICAO; ?></h3>
                            <div class="info-geral-lote">
                                <p>INFORMACOES GERAIS DO LOTE</p>
                            </div>
                            <div class="row">
                                <div class="col-xs-6">
                                    <span class="text-red-desc">Comitente:</span>
                                    <span class="text-black-desc">
                                        <?php $comitente_name = $lote->NOME_FANTASIA; ?>
        <?php if ($lote->TIPO == 'CO' && $lote->COMITENTE_ID > 0 && isset($comitentes[$lote->COMITENTE_ID])) { ?>
            <?php $comitente_name = $comitentes[$lote->COMITENTE_ID]->RAZAO; ?> 
        <?php } ?>          
        <?php echo $comitente_name; ?>
                                    </span>
                                </div>
                                <div class="col-xs-6">
                                    <span class="text-red-desc">Horário:</span>
                                    <span class="text-black-desc"><?php echo substr(extract_time($lote->FECHAMENTO), 0, 5); ?></span>
                                </div>
                                <div class="col-xs-6">
                                    <span class="text-red-desc">Data de abertura:</span><span class="text-black-desc"><?php echo extract_data($lote->CRIADO, '/'); ?></span>
                                </div>
                                <div class="col-xs-6">
                                    <span class="text-red-desc">Lance Inicial:</span><span class="text-black-desc">R$ <?php echo number_format($lote->LANCE_INICIAL, 2, ',', '.'); ?></span>
                                </div>
                                <div class="col-xs-6">
                                    <span class="text-red-desc">Visitacao:</span><span class="info-text-regras2"><?php echo $lote->INFO_VISITACAO; ?></span>
                                </div> 
                                <div class="col-xs-6">   
                                    <span class="text-red-desc">Retirada:</span><span class="info-text-regras2"><?php echo $lote->INFO_RETIRADA; ?></span>
                                </div>
                                <div class="col-xs-12"> 
                                    <span class="text-red-desc">Informacoes extra:</span><span class="info-text-regras2"><?php echo $lote->INFO; ?></span>
                                </div>
                            </div>
                            <div class="clearfix"></div>


                            <div class="info-geral-lote">
                                <p>DESCRICAO DETALHADA</p>
                            </div>
                            <div class="desc-itens">
                                <p style="max-width: 100%;"><?php echo $lote->DESCRICAO_DETALHADA; ?></p>
                            </div>
                        </div>
                    </div> 

                </li>




                <?php
                $cont +=1;
                if ($cont == 4) {
                    // $cont = 0;
                }
            endforeach;
            ?>
        <?php endif; ?>
        <?php
        if ((4 - $cont) > 0) {
            $empty_lotes = (12 - $cont);
            for ($i = 0; $i < $empty_lotes; $i++) {
                ?>
                <li class="col-md-4 col-lg-3 col-sm-4  col-xs-12 emptyBox">
                    <div class="box-lote-maxlive">
                        <div class="data-info">
                <?php echo add_image('logo.png'); ?>
                        </div>
                    </div>
                </li>
        <?php
    }
}
?>
    </ul>
</div>
<!--PAINEL  -->
<div class="col-md-4 col-lg-3 col-xs-12 col-sm-4 box-painel-2" >
    <div class="navbar-painel-2">
        <div class="header-2">
            <a href="#showPainel" data-trigger="show-box"  data-id="<?php ?>"
               data-target="box-painel-2" class="bt-painel-settings"> <i
                    class="fa fa-cog"></i> <i class="fa fa-times hide"></i></a>
            <h3 class="pull-left">Painel do Lance</h3>
<?php if (userData()->id == 0): ?>
                <a href="<?php echo site_url(BASE_URL_USER . '/login?r=' . uri_string()); ?>" class="login-user-painel">LOGIN</a>
            <?php else: ?>
                <div class="login-user-painel">
                    <a href="<?php echo site_url(BASE_URL_USER . '/painel'); ?>" class="login-user-painel"><?php echo userData()->login; ?></a>
                </div>	
<?php endif; ?>

            <div class="clearfix"></div>
        </div>
        <div class="painel-info-actions">
            <div class="bt bt-painel">
                <?php /* check user loggdein */ $has_settings_favotites = $has_show_hide_favorites = 'show-message-login'; ?>
<?php if ((userData()->group == 'user' || userData()->group == 'member')): ?>
    <?php $has_show_hide_favorites = 'show-hide-fav';
    $has_settings_favotites = 'settings-fav';
    ?> 
<?php endif; ?>

                <span class="bt-label">SOMENTE<br/> FAVORITOS</span> <span
                    class="btn-on-off" <?php echo $has_show_hide_favorites; ?>><i class="fa fa-star-o i-on"></i></span>
            </div>
            <div class="bt bt-painel">
                <span class="bt-label">Gerenciar </br> FAVORITOS</span> <span
                    class="btn-on-off" <?php echo $has_settings_favotites; ?>><i class="fa fa-cog i-on"></i></span>
            </div>
            <div class="bt bt-painel">
                <span class="bt-label">exibir <br/>fotos</span> 
                <span class="btn-ico btn-on-off images"><i
                        class="fa fa-camera i-on"></i></span>
            </div>
            <div class="bt bt-painel">
                <span class="bt-label">ÁUDIO <br/> LEILÃO</span> 
                <span class="btn-ico btn-on-off"><i
                        class="fa fa-volume-up i-on"></i></span>
            </div>

            <div class="info-lances-plus-minus-painel">
                <span class="info-lances-painel lances-superados lc-plus"><?php echo str_num_lote_pad($lances_ganhadores, 3); ?><i
                        class="fa fa-thumbs-o-up"></i></span> <span
                    class="label-lances-superados lc-plus"> Lances<br /> Ganhadores
                </span> <span class="info-lances-painel lances-superados lc-minus"><?php echo str_num_lote_pad($lances_superados, 3); ?><i
                        class="fa fa-thumbs-o-down"></i></span> <span
                    class="label-lances-superados lc-minus"> Lances<br /> superados
                </span>
                <div class="clearfix"></div>
            </div>

        </div>
        <div class="slide-painel">
            <?php foreach ($lotes as $key => $plote): ?>
                <?php $date_end = $plote->FECHAMENTO; ?> 
                <?php $rw = !is_null($plote->TEMPO_EXTRA) ? $plote->TEMPO_EXTRA : false; ?>
                <?php if ($rw && strtotime($plote->FECHAMENTO) < $plote->TEMPO_EXTRA): ?>
                    <?php // $is_show_lance = compare_date_max(date('Y-m-d H:i:s'), $lote->TEMPO_EXTRA); ?> 
                    <?php $date_end = date('Y-m-d H:i:s', $plote->TEMPO_EXTRA); ?> 
    <?php endif; ?>
    <?php $_hide = ''; ?>
    <?php if ($key == 0): ?>
        <?php $_hide = 'active'; ?>
    <?php endif; ?>
                <div dada-le-id="<?php echo $plote->LEILAO_ID; ?>" data-lote-id="<?php echo $plote->ID; ?>" class="slide-painel-item panel-lote-<?php echo $plote->ID; ?> <?php echo $_hide; ?>">



                    <div class="maxlive-info-lote">
                        <span class="num-lote-label">LOTE <?php echo str_num_lote_pad($plote->NUM_LOTE); ?></span>
                        <span class="group-label-label"> G1 </span>
                        <div class="time-count-maxlive pull-right">
                            <span class="time-img"> <img src="/public/images/icon-time-lance.png"></span>&nbsp;
    <?php if (is_null($plote->VENDIDO)): ?>
                                <span class="time-lance" data-lote-id="<?php echo $plote->ID; ?>" data-count="<?php echo $date_end; ?>"></span>
    <?php else: ?>
                                <span class="time-lance"><?php echo Utils::message('lote_closed'); ?></span>
                        <?php endif; ?>
                        </div>		
                    </div>
                    <div class="maxlive-descricao-lote">
                        <strong> <?php echo $plote->DESCRICAO; ?></strong> <br />
                        <p><?php echo $plote->SUB_DESCRICAO; ?> Local: <?php echo $plote->LOCALIZACAO; ?> - <?php echo $plote->UF; ?></p>
                            <?php $lmsg = is_null($plote->VENDIDO) ? Utils::message('lote_opened') : Utils::message('lote_closed'); ?>
                        <span class="status-lote-maxlive open"><?php echo $lmsg; ?></span> 
                        <span class="maxlive-status-icons"> 
                            <?php if (!empty($plote->DESCRICAO_DETALHADA)): ?>
                                <a href="#detalhes_<?php echo $plote->ID; ?>" class="icon-status detail-maxlive" ></a>
                            <?php endif; ?>
                            <?php if (!empty($plote->IMAGENS)): ?>
                                <a href="#gallery" class="icon-status gallery-maxlive" data-images='<?php render_to_gallery_painel($plote->IMAGENS); ?>'></a>
    <?php endif; ?>
    <?php if (!empty($plote->LINK)): ?>
                                <a href="#videos" class="icon-status video-maxlive"></a>
    <?php endif; ?>
                            <a href="#lances" data-trigger-get-info-lances lote-id="<?php echo $plote->ID; ?>" class="painel-info-num-lances" title="Lances Ofertados"><i class="fa fa-list"></i> <span><?php echo $plote->LANCES; ?></span></a>

                        </span>
                    </div>

                    <div class="maxlive-price">
                        <div>
                            <p class="text-incr">
                                <span>INCREMENTO:</span><span class="text-incr-valor">R$ 
                                    <span class="incremento-price"><?php echo number_format($plote->INCREMENTO, 2, ',', '.'); ?></span></span>
                            </p>
                        </div>
                        <div class="box-lance-atual-text yellow-claro">
                            <span class="lance-atual-black yellow-esc">PROXIMA OFERTA</span>
                            <div class="box-info-price">
                                <span class="valor-yellow">R$ <span class="next-price" data-next-price-id="<?php echo $plote->ID; ?>" ><?php
    $lance = $plote->LAST_LANCE == null ? $plote->LANCE_INICIAL : $plote->LAST_LANCE + $plote->INCREMENTO;
    echo number_format(($lance), 2, ',', '.');
    ?></span></span>

                            </div> 
                            <div title="<?php echo lang_system('title_info_lance_auto'); ?>" class="lance-automatic-box">
                                R$ <span class="lance-automatic-value"></span>
                            </div>              
                        </div>
                        <div class="maxlive-btn-efetuar-lances">


                            <?php
                            $bid_click = $bid_permission = 'show-message-login';
                            if (userData()->id > 0 && (userData()->group == 'user' || userData()->group == 'admin' )) {
                                $bid_permission = 'no-lance-user';
                            }
                            if (userData()->id > 0 && (userData()->group == 'member') && isEnabled(userData()->id, $lote->LEILAO_ID)) {

                                $bid_permission = '';
                                $bid_click = ' bid-click';
                            }
                            ?>

                        </div>
                        <?php if (is_null($plote->VENDIDO)) { ?>
        <?php $lotes_auto_user = hasAutoLance(userData()->id); ?>
        <?php $on_off_auto_lance = 'off'; ?>
        <?php if (in_array($plote->ID, $lotes_auto_user)): ?>
            <?php $on_off_auto_lance = 'on'; ?>
        <?php endif; ?>
                            <span class="box-maxlive-lance-automatico box-lance-btn-lanceauto"> 
                                <span class="text-auto">LANCE AUTOMATICO</span> 
                                <span class="btn-ativar">
                                    <!-- add-lance-automatic -->
                                    <span  auto-id="<?php echo $plote->ID; ?>"  class="btn-lance-aut <?php echo isAutoLance(userData()->id, $plote->ID) ? 'on' : ''; ?>">A</span>
                                </span>
                                <span class="text-off">OFF</span>
                            </span>
                            <div class="box-buttons-auto-lance">
                                <div class="blocked-lance <?php echo isAutoLance(userData()->id, $plote->ID) ? '' : 'hide'; ?>">Lance Automatico</div> 
                                <a <?php echo $bid_permission; ?>  href="#" bid-id="<?php echo $plote->ID; ?>" class="btn-lances <?php echo $bid_click; ?>" ival="1">+1X</a>
                                <a <?php echo $bid_permission; ?>  href="#" bid-id="<?php echo $plote->ID; ?>" class="btn-lances <?php echo $bid_click; ?>"  ival="2">+2X</a> 
                                <a  <?php echo $bid_permission; ?>  href="#" bid-id="<?php echo $plote->ID; ?>" class="btn-lances <?php echo $bid_click; ?>" ival="5">+5X</a>
                                <a	<?php echo $bid_permission; ?>  href="#resetLance" class="btn-lances minimo-voltar" close-id="<?php echo $plote->ID; ?>" resetBids><span>Minimo <br />
                                        VOLTAR
                                    </span></a>

                                <?php if (userData()->id === 0): ?>
                                    <a href="<?php echo site_url(BASE_URL_USER . '/login?r=' . uri_string()); ?>" class="btn-login-lances">LOGIN</a>
                                <?php endif; ?>
                                <?php if (userData()->id > 0 && (userData()->group == 'user' || userData()->group == 'admin')): ?>
                                    <a no-lance-user leilao-id="<?php echo $leilao_id; ?>" lance-lote-id="<?php echo $lotes['1']->ID; ?>"  href="#" class="btn-login-lances">HABIL.</a>
        <?php endif; ?>
        <?php if (userData()->id > 0 && (userData()->group == 'member') && !isEnabled(userData()->id, $leilao_id)): ?>
                                    <a role="previewCondicoes" l-id="<?php echo $leilao_id; ?>" u-id="<?php echo userData()->id; ?>"  href="#" class="btn-login-lances">HABIL.</a>
                                <?php endif; ?>
        <?php if (userData()->id > 0 && (userData()->group == 'member') && isEnabled(userData()->id, $leilao_id)): ?>
                                    <a addLance leilao-id="<?php echo $leilao_id; ?>" lance-lote-id="<?php echo $plote->ID; ?>" 
                                       href="#" class="btn-login-lances"><span class="loading-button"></span>
                                        <span class="button-lance-label">LANCE</span></a>
                            <?php endif; ?>

                            </div>
                            <div class="clearfix"></div>
                        <?php }else { ?>
                            <div class="label label-danger label-lote-closed"><?php echo $plote->CONDICIONAL == 'S' ? lang_system('lote_closed_conditional'):Utils::message('lote_sold'); ?></div>
    <?php } ?>
    <?php if (userData()->id > 0 && (userData()->group == 'member') && !isEnabled(userData()->id, $plote->LEILAO_ID)): ?>   
                            <div class="box-no-login-info">Para efetuar seu lance, faça o login e
                                solicite sua habilitação.</div>
    <?php endif; ?>  
                    </div>
                </div>

<?php endforeach; ?>
        </div>
        <div class="clearfix"></div>
    </div>
